package com.msb.msbdongbaocommonutil;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;

public class JwtUtil {

    private static final String secret = "asdsad";

    public static String createToken(String subject){
        String token = Jwts.builder().setSubject(subject).
                setExpiration(new Date(System.currentTimeMillis()+1000*60*60)).
                signWith(SignatureAlgorithm.HS256, secret).
                compact();
        return token;
    }

    public static String parseToken(String token){
        Claims body = Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody();
        String subject = body.getSubject();
        return subject;
    }
}
